package com.ruoyi.iot.dataprocessing.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.iot.api.domain.PushInfo;
import net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/push")
public class PushComtroller {
    @Autowired
    private MqttClientTemplate client;

    @InnerAuth
    @PostMapping("/pushHandler")
    public R pushHandler(@RequestBody PushInfo pushInfo){
        client.publish(pushInfo.getTopic(), pushInfo.getPayload());
        return R.ok();
    }
}
